<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends CommonAction {
    //后台界面与系统信息
    public function info(){
        $this->count_admin=M('user')->count();
        $this->count_content=M('content')->count();
        $this->user = D('UserRelation')->field('password', true)->relation(true)->where(array('username'=>array('eq', session('username'))))->select(); //大小写
        $this->display();
    }
    //动态栏目从数据库读取
    public function index(){
        import('Class.Category',APP_PATH);
        $cate=M('category')->order('sort ASC')->select();
        $this->cate=Category::unlimitedforlayer($cate);
        $this->display();
	}
    //退出系统
	public function logout(){
		session_unset();
		session_destroy();
		if(!isset($_SESSION['uid'])){
			$this->redirect(GROUP_NAME.'/Login/index');
		}
	}
    //管理员信息
    public function admin_info()
    {
        $this->name=M('user')->where(array('username' => array('eq', session('username'))))->select();
        $this->display();
    }
    //管理员密码更改模板
    public function admin_pwd()
    {
        $this->name=M('user')->where(array('username' => array('eq', session('username'))))->select();
        $this->display();
    }
    /*
   * 管理员信息更改*/
    public function edit_admin_info()
    {
        /* bashqurghuchigha munasiwetlik uqurlarni oqup aldim*/
        $old_user = M('user')->where(array('username' => array('eq', session('username'))))->find();
        /*
         * maxpi numurini sandangha selishturdum*/
     if(isset($_POST['old_passsword'])){
         if ($old_user['password'] != I('old_passsword', '', 'md5')) {
             $this->error('您的久密码不准');
         }
         /*ikki parolini selishturdum*/
         if (I('new_passsword_1') != I('new_passsword_2')) {
             $this->error('密码确认失败');
         }


         $data = array(
             'id' => $old_user['id'],
             'password' => I('new_passsword_2', '', 'md5'),
         );

     }else{

         $data = array(
             'id' => $old_user['id'],
             'realname' => I('realname'),
             'email' => I('email'),
             'phone' => I('phone'),
         );
     }


        /*
         * uchurni sanghangha qoshtum*/
        if (M('user')->save($data)) {
            echo "<script> alert('修改成功')</script>";
        } else {
            $this->error('修改失败');
        }


    }
}